import rxAjax from '@/assets/js/ajax.js';
import {Util} from '@lowcode/jpaas-common-lib';

//自定查询 api接口
export const FormCustomQueryApi = {};

FormCustomQueryApi.baseUrl= '/api-form/form/core/formCustomQuery';
FormCustomQueryApi.exportUrl= FormCustomQueryApi.baseUrl + '/listExport';


FormCustomQueryApi.doImport=function(formData,callback) {
  var url= FormCustomQueryApi.baseUrl+"/doImport";
  return rxAjax.upload(url,formData,callback);
}


FormCustomQueryApi.doExport = function(solutionIds) {
  solutionIds=Util.encryptWord(solutionIds);
  window.location.href='/api/api-form/form/core/formCustomQuery/doExport?solutionIds=' + solutionIds;

}
FormCustomQueryApi.findColumnList=function (parameter) {
    var url= '/api-form/form/core/sysDb/findColumnList';
    return rxAjax.postJson(url,parameter).then (res => {
        return res
    })
}

//查询列表
FormCustomQueryApi.query=function (parameter) {
  var url= FormCustomQueryApi.baseUrl + '/query';
  return rxAjax.postJson(url,parameter).then (res => {
    return res.result
  })
}

/**
* 获取单记录
* @param pkId
* @returns {*}
*/
FormCustomQueryApi.get =function(pkId) {
  var url= FormCustomQueryApi.baseUrl + '/get?pkId=' + pkId;
  return rxAjax.get(url);
}

FormCustomQueryApi.preview =function(pkId) {
  var url= FormCustomQueryApi.baseUrl + '/preview?pkId=' + pkId;
  return rxAjax.get(url);
}

//保存数据
FormCustomQueryApi.save =function(parameter) {
  var url= FormCustomQueryApi.baseUrl + '/save';
  return rxAjax.postJson(url,parameter);
}

//删除数据
FormCustomQueryApi.del =function(parameter) {
  var url= FormCustomQueryApi.baseUrl + '/del';
  return rxAjax.postUrl(url,parameter);
}

//系统常量
FormCustomQueryApi.getConstants =function () {
  var url= FormCustomQueryApi.baseUrl + '/getConstantItem';
  return rxAjax.get(url);
}

/**
 * 加载自定义查询。
 */
FormCustomQueryApi.getByKey=function(params) {
    var url= "/api-form/form/core/formCustomQuery/getByKey";
    return rxAjax.get(url,params);
}

//执行自定义SQL
FormCustomQueryApi.doQuery=function(alias,parameter){
    var url = FormCustomQueryApi.baseUrl + '/queryForJson_'+alias;
    return rxAjax.postForm(url,parameter);
}

//获取表与字段前缀
FormCustomQueryApi.getPrefix=function(){
    var url = FormCustomQueryApi.baseUrl + '/getPrefix';
    return rxAjax.get(url);
}

FormCustomQueryApi.saveList=function(parameter){
    var url = FormCustomQueryApi.baseUrl + '/saveList';
    return rxAjax.postJson(url,parameter);
}

FormCustomQueryApi.update=function(parameter){
    var url = FormCustomQueryApi.baseUrl + '/update';
    return rxAjax.postJson(url,parameter);
}

FormCustomQueryApi.updExport =function(ids) {
    var url= FormCustomQueryApi.baseUrl + '/updExport';
    return rxAjax.postForm(url,{ids:ids});
}

FormCustomQueryApi.getByAlias =function(record) {
    var url= "/api-system/system/core/sysDic/getByAlias?alias="+record.configs.dic+"&i18nTransform=true"
    return rxAjax.get(url);
}

FormCustomQueryApi.getUserRels =function() {
    var url= "/api-user/user/org/osRelType/getUserRels"
    return rxAjax.get(url);
}

//变更分类
FormCustomQueryApi.changeCategory=function(ids,categoryId){
    var url= FormCustomQueryApi.baseUrl+'/changeCategory';
    return rxAjax.postForm(url, {ids:ids,categoryId:categoryId});
}
export  default FormCustomQueryApi;

